<template>
	<view class="content fofa poRel">
		<tabnav title="合同详情" :col="back" left_go="/pages/index/index" :go="true"></tabnav>
		<view v-if="list">
			<view class="wid100" :style="'background-color: '+back+';'" style="height: 300rpx;">
				<view class="wid90 mar coFFF">
					<view class="dis disAl foSi40">
						<view style="width: 20%;" class="dis disAl disJuC">
							<image src="../../static/wc/saoma.png" style="width: 80rpx;height: 80rpx;"></image>
						</view>
						<view>{{list.tips}}</view>
					</view>
					<view class="dis disAl foSi30 mar-top10">
						<view style="width: 20%;"></view>
						<view>剩余时间: {{list.deadline}}</view>
					</view>
				</view>
			</view>
			<view class="wid90 mar bacFFF borRad20" style="margin-top: -120rpx;">
				<view class="wid90 mar">
					<view style="height: 60rpx;"></view>
					<view class="hei80 dis disAl disJuC foSi35 fowe600">{{list.contract_name}}</view>
					<view class="dis disJuC mar-top40">
						<image :src="aurl+icon_list.jianyan2" style="width: 530rpx;height: 225rpx;"></image>
					</view>
					<view style="border-bottom: 1rpx solid #e6dede;height: 60rpx;"></view>
					<view v-for="(item,index) in list.recipient" :key="index" 
					class="hei80 dis disAl disJuC foSi30 fowe600" style="border-bottom: 1rpx solid #e6dede;">
						<view>签署方</view>
						<view class="mar-left30">{{item.roleName?item.roleName:'待补充信息'}}</view>
					</view>
				</view>
				<view style="height: 80rpx;"></view>
			</view>
			<view class="wid90 mar bacFFF dis disAl disJuC hei80 mar-top30 borRad10 foSi30" 
			:style="'color: '+back+';'" @click="buchong">补充信息</view>
		</view>
	</view>
</template>

<script>
	import tabnav from "../common/tabnav/tabnav.vue"
	export default {
		components: {
			tabnav,
		},
		data() {
			return {
				aurl:this.global.url,
				back: uni.getStorageSync('back'),
				backTwo: uni.getStorageSync('backTwo'),
				pdfurl: '',
				tops: '',
				erImage: '',
				list: [],
				flowId: '',
				icon_list:{
					jianyan2:'/addon/qianyu_dzq/wechatimg/jianyan2.png',
				}
			}
		},
		onLoad(option) {
			let that = this
			console.log('接收的参数')
			that.id = option.id
		},
		onShow(){
			let that = this
			var token = uni.getStorageSync('inuse_userinfo_token')
			if(!token){
				that.tiaozhuan('/pages/login/login')
			}else{
				this.pdfurl = uni.getStorageSync('contract_detail')
				console.log('pdfurl=', this.pdfurl)
				that.getFlowId()
				that.getMobile()
			}
		},
		created() {
			uni.getSystemInfo({
				success: (e) => {
					console.log(e)
					this.tops = e.statusBarHeight
				}
			})
		},
		methods: {
			fenxiang(){
				let that = this
				wx.downloadFile({
				   url: that.erImage,
				   success: (res) => {
					 wx.showShareImageMenu({
					   path: res.tempFilePath
					 })
				   }
				})
			},
			getMobile(){
				let that = this
				uni.request({
					url: that.global.url+'api/qianyu_dzq/applet_token_to_userinfo',
					method: 'POST',
					header:{'site-id':that.global.site_id,'token': uni.getStorageSync('inuse_userinfo_token')},
					data: {type: 1},
					success(res) {
					    let result = res.data
					    if(result.code == 1){
							console.log(result.data)
							that.mobile = result.data.mobile
					    }else{
					        uni.showToast({
					            title: result.msg,
					            icon:'none',
								duration: 2000
					        })
					    }
					},
					complete() {
						uni.hideLoading()
					}
				})
			},
			getFlowId(id){
				let that = this
				uni.request({
					url: that.global.url+'api/qianyu_dzq/applet_get_flowid_to_did',
					method: 'POST',
					header:{'site-id':that.global.site_id,'token': uni.getStorageSync('inuse_userinfo_token')},
					data: {id: that.id},
					success(res) {
					    let result = res.data
					    if(result.code == 1){
							console.log(result.data)
							that.flowId = result.data.flowId
							that.getList()
					    }else{
					        uni.showToast({
					            title: result.msg,
					            icon:'none',
								duration: 2000
					        })
					    }
					},
					complete() {
						uni.hideLoading()
					}
				})
			},
			getList() {
				let that = this
				uni.request({
					url: that.global.url+'api/qianyu_dzq/applet_current_details',
					method: 'POST',
					header:{'site-id':that.global.site_id,'token': uni.getStorageSync('inuse_userinfo_token')},
					data: {flowid: that.flowId},
					success(res) {
					    let result = res.data
					    if(result.code == 1){
							console.log(result.data)
							that.list = result.data
					    }else{
					        uni.showToast({
					            title: result.msg,
					            icon:'none',
								duration: 2000
					        })
					    }
					},
					complete() {
						uni.hideLoading()
					}
				})
			},
			buchong(){
				let that = this
				uni.request({
					url: that.global.url+'api/qianyu_dzq/applet_contracts_createsignurls_public',
					method: 'POST',
					header:{'site-id':that.global.site_id,'token': uni.getStorageSync('inuse_userinfo_token')},
					data: {flowid: that.flowId},
					success(res) {
					    let result = res.data
					    if(result.code == 1){
							console.log(result.data)
							var data = result.data
							for (var i=0; i< data.length; i++) {
								if(that.mobile == data[i].mobile){
									that.goNativeindex(data[i].signUrl)
								}
							}
					    }else{
					        uni.showToast({
					            title: result.msg,
					            icon:'none',
								duration: 2000
					        })
					    }
					},
					complete() {
						uni.hideLoading()
					}
				})
			},
			goNativeindex(path){
			    uni.openEmbeddedMiniProgram({
			        appId: 'wxa023b292fd19d41d',// 此为 appid
			        path: path,// 此为路径
			        envVersion:"release",
			        success: res => {
			             // 打开成功
			             console.log("打开成功", res);
			        },
			        fail: err => {
			             console.log(err);
			        }
			    })
			},
			tiaozhuan(url){
				uni.navigateTo({
					url: url
				});
			},
			shouyin(){
				uni.switchTab({
					url: '/pages/index/index'
				});
			},
		}
	}
</script>

<style>
	.content {
		min-height: 100vh;
		background-color: #F4F3F3;
	}
</style>